<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>禁止输入空格</title>
</head>
<body>

<h2>输入框</h2>
<input type="text" id="inputBox" onkeyup="removeSpaces(event)" placeholder="在此输入，禁止空格">

<script>
function removeSpaces(event) {
  var input = event.target.value;
  event.target.value = input.replace(/\s/g, ''); // 使用正则表达式替换空格
}
</script>

</body>
</html>
